//
//  OtherDetailPromotionCell.swift
//  ImGuider X
//
//  Created by 陆涛 on 2018/10/9.
//  Copyright © 2018 imguider. All rights reserved.
//

import UIKit

class OtherDetailPromotionCell: UITableViewCell {

    @IBOutlet weak var headTitleLabel: UILabel!
    
    @IBOutlet weak var headTitleTop: NSLayoutConstraint!
    @IBOutlet weak var cellbottom: NSLayoutConstraint!
    
    @IBOutlet weak var titleLabel: UILabel!
    
    @IBOutlet weak var introLabel: UILabel!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.backgroundColor = kThemeBgColor
    }
    
    var isLast:Bool = false {
        
        didSet {
            
            cellbottom.constant = isLast ? 40 : 24
        }
    }
    
    var isTitleHidden:Bool = false {
        
        didSet {
            
            headTitleLabel.text = isTitleHidden ? nil : LocalizedString("discount_msg")
            headTitleTop.constant = isTitleHidden ? -24 : 0
        }
    }
    
    var promotion:Promotion? {
        
        didSet {
            
            titleLabel.text = "\(promotion?.type ?? "") \(promotion?.name ?? "")"
            
            
            let att = NSMutableAttributedString()
            
            if let detail = promotion?.detail {
                
                att.yy_appendString(detail)
            }
            
            if let useTip = promotion?.useTip {
                
                if att.length > 0 {
                    
                    att.yy_appendString("\n")
                }
                att.yy_appendString(useTip)
            }
            
            att.yy_font = kFont10
            att.yy_lineSpacing = 0
            att.yy_color = UIColor.hexStringToColor(hexString: "#8D979C")
            
            introLabel.attributedText = att
        }
    }
}
